package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.role.AddRoleDTO;
import com.qk.dto.role.QueryPageRoleDTO;
import com.qk.dto.role.UpdateRoleDTO;
import com.qk.entity.Role;
import com.qk.management.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:gzc
 * @Date: 2025/10/06 19:39
 * @Description:
 */
@RestController
@RequestMapping("/roles")
@Slf4j
public class RoleController {

    @Autowired
    private RoleService roleService;
    @GetMapping
    public Result queryListByPage(QueryPageRoleDTO queryPageRoleDTO) {
        log.info("角色分页查询参数：{}", queryPageRoleDTO);
        PageResult<Role> queryListByPageVO = roleService.queryListByPage(queryPageRoleDTO);
        return Result.success(queryListByPageVO);
    }

    @DeleteMapping("/{id}")
    public Result deleteRole(@PathVariable Integer id) {
        log.info("删除参数：{}", id);
        roleService.deleteRole(id);
        return Result.success();
    }

    @PostMapping
    public Result addRole(@RequestBody AddRoleDTO addRoleDTO) {
        log.info("新增参数：{}", addRoleDTO);
        roleService.addRole(addRoleDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id) {
        log.info("查询参数：{}", id);
        Role role = roleService.queryById(id);
        return Result.success(role);
    }

    @PutMapping
    public Result updateById(@RequestBody UpdateRoleDTO updateRoleDTO) {
        log.info("修改参数：{}", updateRoleDTO);
        roleService.updateRole(updateRoleDTO);
        return Result.success();
    }

    @GetMapping("/list")
    public Result queryAll() {
        log.info("查询所有角色信息");
        return  Result.success(roleService.queryAll());
    }
}
